﻿@page "/notification"

@inject NotificationService notificationService

<RadzenExample Name="Notification" Documentation="true">
<div class="row">
    <div class="col-md-6">
        <h3>Info</h3>
        <RadzenButton Text=@($"Show info notification") Style="margin-bottom: 20px; width: 200px"
            Click="@(args => ShowNotification(new NotificationMessage() { Severity = NotificationSeverity.Info, Summary = "Info Summary", Detail = "Info Detail", Duration = 4000 }))" />
        <br />
        <h3>Warning</h3>
        <RadzenButton Text=@($"Show warning notification") Style="margin-bottom: 20px; width: 200px"
            Click="@(args => ShowNotification(new NotificationMessage() { Severity = NotificationSeverity.Warning, Summary = "Warning Summary", Detail = "Warning Detail", Duration = 4000 }))" />
        <br />
        <h3>Error</h3>
        <RadzenButton Text=@($"Show error notification") Style="margin-bottom: 20px; width: 200px"
            Click="@(args => ShowNotification(new NotificationMessage() { Severity = NotificationSeverity.Error, Summary = "Error Summary", Detail = "Error Detail", Duration = 4000 }))" />
        <br />
        <h3>Success</h3>
        <RadzenButton Text=@($"Show success notification") Style="margin-bottom: 20px; width: 200px"
            Click="@(args => ShowNotification(new NotificationMessage() { Severity = NotificationSeverity.Success, Summary = "Success Summary", Detail = "Success Detail", Duration = 4000 }))" />
    </div>
    <div class="col-md-6">
        <h3>Events</h3>
        <RadzenCard style="overflow: auto;height:500px;">
            @foreach (var e in events.OrderByDescending(i => i.Key))
            {
                @e.Value
                <br />
            }
        </RadzenCard>
    </div>
</div>
</RadzenExample>

@code {
    Dictionary<DateTime, string> events = new Dictionary<DateTime, string>();

    async void ShowNotification(NotificationMessage message)
    {
        notificationService.Notify(message);

        events.Add(DateTime.Now, $"{message.Severity} notification");
        await InvokeAsync(() => { StateHasChanged(); });
    }
}
